package edu.hqu.deepspace.controller;

import edu.hqu.deepspace.pojo.Admin;
import edu.hqu.deepspace.pojo.Product;
import edu.hqu.deepspace.pojo.User;
import edu.hqu.deepspace.service.AdminService;
import edu.hqu.deepspace.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Lenovo
 */
@Controller
@RequestMapping("/Admin")
public class UserController {
    @Autowired
    @Qualifier("UserServiceImpl")
    private UserService userService;



    @RequestMapping("/user")
    public String list(Model model){
        System.out.println("方法调用");
        List<User> list =userService.queryUser();
        model.addAttribute("list", list);
        return "User";
    }

    @RequestMapping("/toAddUser")
    public String toAddPaper() {
        return "addUser";
    }

    @RequestMapping("/addUser")
    public String addPaper(User user) {
        System.out.println(user);
        userService.addUser(user);
        return "redirect:/Admin/user";
    }

    @RequestMapping("/toUpdateUser")
    public String toUpdateBook(Model model, String uid) {
        User user = userService.queryUserById(uid);
        System.out.println(user);
        model.addAttribute("Quser",user);
        return "updateUser";
    }

    @RequestMapping("/updateUser")
    public String updateBook(Model model, User user) {
        System.out.println(user);
        userService.updateUser(user);
        User user1 = userService.queryUserById(user.getUid());
        model.addAttribute("user", user1);
        return "redirect:/Admin/user";
    }

    @RequestMapping("/del/{uid}")
    public String deleteUser(@PathVariable("uid") String uid) {
        userService.deleteUser(uid);
        return "redirect:/Admin/user";
    }
    @RequestMapping("/query1")
    public String queryProduct(Model model,String uid){
            User user = userService.queryUserById(uid);
            model.addAttribute("user", user);
            return "queryUser";}

    }

